package de.jenseins.utils.propertytranslator.gui.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JTextField;

import de.jenseins.utils.propertytranslator.gui.FilePicker;
import de.jenseins.utils.propertytranslator.gui.MainFrame;

/**
 * 
 * 
 * @author Jens Greive
 * @since 02.12.2009
 * 
 */
public class OpenPropertyFileListener implements ActionListener {

	private File sourceFile = null;

	private JTextField selectedFileField;

	private MainFrame frame;

	public OpenPropertyFileListener(JTextField textfield, MainFrame frame) {
		this.selectedFileField = textfield;
		this.frame = frame;
	}

	public void actionPerformed(ActionEvent e) {
		sourceFile = FilePicker.getSourceFile();
		if (sourceFile != null) {
			frame.validateGUI();
			selectedFileField.setText(sourceFile.getAbsolutePath());
		}
	}

	public File getSourceFile() {
		return sourceFile;
	}

	public void reset() {
		sourceFile = null;
	}

}
